package com.jse.aop;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.context.request.NativeWebRequest;

//@ControllerAdvice
public class ReturnAspect {

	@ModelAttribute  
    public Object newUser() {  
        System.out.println("============应用到所有@RequestMapping注解方法，在其执行之前把返回值放入Model");  
        return null;  
    }  
  
    @InitBinder  
    public void initBinder(WebDataBinder binder) {  
        System.out.println("============应用到所有@RequestMapping注解方法，在其执行之前初始化数据绑定器");  
    }  
  
    @ExceptionHandler(Exception.class)  
    @ResponseStatus(code=HttpStatus.INTERNAL_SERVER_ERROR,reason="服务出错")  
    public String processUnauthenticatedException(NativeWebRequest request, Exception e) {  
        System.out.println("===========应用到所有@RequestMapping注解的方法，在其抛出UnauthenticatedException异常时执行");  
        System.err.println(e);
        return "error"; //返回一个逻辑视图名  
    }  
    
    
}
